﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenNETCF.IoC;
using MachineSimulator.Presenters;
using MachineSimulator.Views;

namespace MachineSimulator
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            RootWorkItem.Workspaces.Add(headerWorkspace);
            RootWorkItem.Workspaces.Add(bodyWorkspace);

            var infoPresenter = RootWorkItem.Services.AddNew<AgentInfoPresenter>();
            infoPresenter.RestartRequested += new EventHandler(infoPresenter_RestartRequested);
            var p =  RootWorkItem.Services.AddNew<MachinePresenter>();
            p.Invoker = this;
            RootWorkItem.Services.AddNew<SimulationPresenter>();

            this.SuspendLayout();
            headerWorkspace.Show<AgentInfoView>();
            var startView = bodyWorkspace.Show<MachineView>();
            bodyWorkspace.Show<SimulationView>();
            bodyWorkspace.Activate(startView);
            this.ResumeLayout();
        }

        void infoPresenter_RestartRequested(object sender, EventArgs e)
        {
            this.InvokeIfRequired(i =>
                {
                    this.Close();
                    Application.Exit();
                });
        }
    }
}
